package tosp;

import java.util.TreeSet;

import tosp.job.JobAdapter;

public class Magazine extends JobAdapter {
	int maxSize;
	TreeSet<Integer> tools;

	public Magazine(int[] tools, int maxSize) {
		this.tools = new TreeSet<Integer>();
		for (int i=0; i<tools.length; i++) {
			this.tools.add(tools[i]);
		}
		this.maxSize = maxSize;
	}
	
	/**
	 * Copy Constructor
	 * @param other
	 */
	public Magazine(Magazine other) {
		this.tools = (TreeSet<Integer>) other.tools.clone();
		this.maxSize=other.maxSize;
	}
	
	public boolean addTool(int newTool) {
		if (tools.size()+1 > maxSize)
			return false;
		this.tools.add(newTool);
		return true;
	}
	
	public void removeTool(int t) {
		tools.remove(Integer.valueOf(t));
		//tools.remove(tools.indexOf(t));
	}
	
	public int getFreeSlots() {
		return maxSize-tools.size();
	}

	public int getNumberOfTools() {
		return tools.size();
	}

	public int[] getTools() {
		int[] tools = new int[this.tools.size()];
		int j=0;
		for (Integer i: this.tools) {
			tools[j] = i.intValue();
			j++;
		}
		return tools;
	}

}
